package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.exceptions.LeaseException;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.xerial.snappy.SnappyBundleActivator;

/**
 * projectName: com.atguigu.lease.common.springmvc
 *
 * @author: 赵伟风
 * description: 全局异常处理类
 */

@RestControllerAdvice
public class GlobalExceptionHandlers {

    //定义个最大的异常处理,返回通用失败码即可
    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        e.printStackTrace();
        String message = e.getMessage();
        return Result.fail(message);
    }


    @ExceptionHandler(LeaseException.class)
    public Result LeaseExceptionHandler(LeaseException e){
        e.printStackTrace();
        ResultCodeEnum resultCodeEnum = e.getResultCodeEnum();
//        Integer code = resultCodeEnum.getCode();
//        String message = resultCodeEnum.getMessage();
        return Result.build(null,resultCodeEnum);
    }
}
